package com.example.recuitactivity.myMainActivity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.recuitactivity.R;
import com.example.recuitactivity.viewTables.ViewAdminsTableActivity;
import com.example.recuitactivity.viewTables.ViewBrowsesTableActivity;
import com.example.recuitactivity.viewTables.ViewCandidatesTableActivity;
import com.example.recuitactivity.viewTables.ViewCollectsTableActivity;
import com.example.recuitactivity.viewTables.ViewDeliversTableActivity;
import com.example.recuitactivity.viewTables.ViewEnterprisesTableActivity;
import com.example.recuitactivity.viewTables.ViewInterviewsTableActivity;
import com.example.recuitactivity.viewTables.ViewPostsTableActivity;
import com.example.recuitactivity.viewTables.ViewResumesTableActivity;

public class AdminMainActivity extends AppCompatActivity {
    private Button btn_admins,btn_candidates,btn_enterprises,btn_delivers,btn_resumes,btn_interviews,btn_posts,btn_collects,btn_browses;

    private View.OnClickListener listener=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent=null;
            switch (view.getId()){
                case R.id.btn_admins:
                    intent=new Intent(AdminMainActivity.this, ViewAdminsTableActivity.class);
                    break;
                case R.id.btn_candidates:
                    intent=new Intent(AdminMainActivity.this, ViewCandidatesTableActivity.class);
                    break;
                case R.id.btn_enterprises:
                    intent=new Intent(AdminMainActivity.this, ViewEnterprisesTableActivity.class);
                    break;
                case R.id.btn_delivers:
                    intent=new Intent(AdminMainActivity.this, ViewDeliversTableActivity.class);
                    break;
                case R.id.btn_resumes:
                    intent=new Intent(AdminMainActivity.this, ViewResumesTableActivity.class);
                    break;
                case R.id.btn_interviews:
                    intent=new Intent(AdminMainActivity.this, ViewInterviewsTableActivity.class);
                    break;
                case R.id.btn_posts:
                    intent=new Intent(AdminMainActivity.this, ViewPostsTableActivity.class);
                    break;
                case R.id.btn_collects:
                    intent=new Intent(AdminMainActivity.this, ViewCollectsTableActivity.class);
                    break;
                case R.id.btn_browse:
                    intent=new Intent(AdminMainActivity.this, ViewBrowsesTableActivity.class);
                    break;
            }
            startActivity(intent);
        }
    };

    public void initUI(){
        btn_admins=(Button) findViewById(R.id.btn_admins);
        btn_candidates=(Button) findViewById(R.id.btn_candidates);
        btn_enterprises=(Button) findViewById(R.id.btn_enterprises);
        btn_delivers=(Button) findViewById(R.id.btn_delivers);
        btn_resumes=(Button) findViewById(R.id.btn_resumes);
        btn_interviews=(Button) findViewById(R.id.btn_interviews);
        btn_posts=(Button) findViewById(R.id.btn_posts);
        btn_collects=(Button) findViewById(R.id.btn_collects) ;
        btn_browses=(Button) findViewById(R.id.btn_browse);

        btn_admins.setOnClickListener(listener);
        btn_candidates.setOnClickListener(listener);
        btn_enterprises.setOnClickListener(listener);
        btn_delivers.setOnClickListener(listener);
        btn_resumes.setOnClickListener(listener);
        btn_interviews.setOnClickListener(listener);
        btn_posts.setOnClickListener(listener);
        btn_collects.setOnClickListener(listener);
        btn_browses.setOnClickListener(listener);
    }

    public void initDatas(){
        String username=getIntent().getExtras().getString("username");
        ActionBar actionBar=getSupportActionBar();
        actionBar.setTitle("欢迎  "+username);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_admin_main);
        initDatas();
        initUI();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate( R.menu.main_menu, menu );
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch ( item.getItemId() ) {
            case R.id.menu_logout:
                Toast.makeText(this,"注销成功！",Toast.LENGTH_SHORT).show();
                finish();
        }
        return super.onOptionsItemSelected(item);
    }

}